/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 28/08/2012, 13:42:27
 */
package br.com.petshop.dao.frames;

import br.com.petshop.dao.AgendaDAO;
import br.com.petshop.entidades.Agenda;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Sidney
 */
public class Principal extends javax.swing.JFrame {

    /** Creates new form Principal */
    public Principal() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        refreshAgenda();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jl_tituloPrincipal = new javax.swing.JLabel();
        JP_Botoes = new javax.swing.JPanel();
        jb_usuario = new javax.swing.JButton();
        jb_animal = new javax.swing.JButton();
        jb_clientes = new javax.swing.JButton();
        jb_agenda = new javax.swing.JButton();
        jb_produtos = new javax.swing.JButton();
        jb_vendas = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAgenda = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Pet Shop - Sistema de Vendas e Agendamento");

        jl_tituloPrincipal.setFont(new java.awt.Font("Verdana", 0, 14));
        jl_tituloPrincipal.setText("Bem Vindo ao Sistema de Vendas e Agendamentos - Pet Shop");

        JP_Botoes.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jb_usuario.setBackground(new java.awt.Color(255, 255, 255));
        jb_usuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/usuario3.png"))); // NOI18N
        jb_usuario.setText("Usuario");
        jb_usuario.setToolTipText("Usuario do Sistema");
        jb_usuario.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_usuario.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_usuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_usuarioActionPerformed(evt);
            }
        });

        jb_animal.setBackground(new java.awt.Color(255, 255, 255));
        jb_animal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/animals3.png"))); // NOI18N
        jb_animal.setText("Animais");
        jb_animal.setToolTipText("Cadastro e Pesquisa Por Animal");
        jb_animal.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_animal.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_animal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_animalActionPerformed(evt);
            }
        });

        jb_clientes.setBackground(new java.awt.Color(255, 255, 255));
        jb_clientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cliente.png"))); // NOI18N
        jb_clientes.setText("Cliente");
        jb_clientes.setToolTipText("Cadastro de Clientes");
        jb_clientes.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_clientes.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_clientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_clientesActionPerformed(evt);
            }
        });

        jb_agenda.setBackground(new java.awt.Color(255, 255, 255));
        jb_agenda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/agenda.png"))); // NOI18N
        jb_agenda.setText("Agenda");
        jb_agenda.setToolTipText("Agenda do Dia");
        jb_agenda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_agenda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_agenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_agendaActionPerformed(evt);
            }
        });

        jb_produtos.setBackground(new java.awt.Color(255, 255, 255));
        jb_produtos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/produto.png"))); // NOI18N
        jb_produtos.setText("Produtos");
        jb_produtos.setToolTipText("Produtos Disponiveis");
        jb_produtos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_produtos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_produtos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_produtosActionPerformed(evt);
            }
        });

        jb_vendas.setBackground(new java.awt.Color(255, 255, 255));
        jb_vendas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/money.gif"))); // NOI18N
        jb_vendas.setText("Vendas");
        jb_vendas.setToolTipText("Vendas");
        jb_vendas.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jb_vendas.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jb_vendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_vendasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JP_BotoesLayout = new javax.swing.GroupLayout(JP_Botoes);
        JP_Botoes.setLayout(JP_BotoesLayout);
        JP_BotoesLayout.setHorizontalGroup(
            JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_BotoesLayout.createSequentialGroup()
                .addGap(152, 152, 152)
                .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jb_usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_agenda, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jb_animal, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jb_produtos, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JP_BotoesLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jb_vendas, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JP_BotoesLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jb_clientes, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(173, Short.MAX_VALUE))
        );

        JP_BotoesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jb_agenda, jb_animal, jb_clientes, jb_produtos, jb_usuario, jb_vendas});

        JP_BotoesLayout.setVerticalGroup(
            JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JP_BotoesLayout.createSequentialGroup()
                .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(JP_BotoesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jb_animal, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jb_produtos, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, JP_BotoesLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jb_clientes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jb_usuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(JP_BotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jb_vendas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jb_agenda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(54, Short.MAX_VALUE))
        );

        JP_BotoesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jb_agenda, jb_animal, jb_clientes, jb_produtos, jb_usuario, jb_vendas});

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Agenda do Dia", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Verdana", 2, 14))); // NOI18N

        tblAgenda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblAgenda);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(106, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jl_tituloPrincipal))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(JP_Botoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jl_tituloPrincipal)
                .addGap(18, 18, 18)
                .addComponent(JP_Botoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-647)/2, (screenSize.height-639)/2, 647, 639);
    }// </editor-fold>//GEN-END:initComponents

    private void jb_usuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_usuarioActionPerformed
        frmUsuario usuario = new frmUsuario(this, true);
        usuario.setVisible(true);
    }//GEN-LAST:event_jb_usuarioActionPerformed

    private void jb_animalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_animalActionPerformed
        frmAnimal animal = new frmAnimal(this, true);
        animal.setVisible(true);
    }//GEN-LAST:event_jb_animalActionPerformed

    private void jb_clientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_clientesActionPerformed
        frmCliente cliente = new frmCliente(this,true);
        cliente.setVisible(true);
    }//GEN-LAST:event_jb_clientesActionPerformed

    private void jb_agendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_agendaActionPerformed
        frmAgenda agenda = new frmAgenda(this, true);
        agenda.setVisible(true);
    }//GEN-LAST:event_jb_agendaActionPerformed

    private void jb_produtosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_produtosActionPerformed
        frmProduto produtos = new frmProduto(this, true);
        produtos.setVisible(true);
    }//GEN-LAST:event_jb_produtosActionPerformed

    private void jb_vendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_vendasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jb_vendasActionPerformed

    public void refreshAgenda(){
        
       try{
            List <Agenda> ag = new AgendaDAO().getAgendamentos();
            tblAgenda.setModel(new MyTableModel(Agenda.class, ag, tblAgenda));
       }catch(Exception ex){
           ex.printStackTrace();
       }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel JP_Botoes;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jb_agenda;
    private javax.swing.JButton jb_animal;
    private javax.swing.JButton jb_clientes;
    private javax.swing.JButton jb_produtos;
    private javax.swing.JButton jb_usuario;
    private javax.swing.JButton jb_vendas;
    private javax.swing.JLabel jl_tituloPrincipal;
    private javax.swing.JTable tblAgenda;
    // End of variables declaration//GEN-END:variables
}
